<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring 事务传播行为完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 10px;
            right: 15px;
            font-size: 0.75rem;
            color: #858585;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .propagation-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 0.5rem 1.5rem;
            border-radius: 50px;
            display: inline-block;
            font-weight: 600;
            box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
        }
        
        .section-title {
            position: relative;
            padding-left: 1rem;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 100%;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .mermaid {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 1.5rem;
            margin-bottom: 1rem;
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .highlight-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 700;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fadeInUp">
                <div class="mb-6">
                    <i class="fas fa-exchange-alt text-5xl opacity-80"></i>
                </div>
                <h1 class="text-5xl font-bold mb-6">Spring 事务传播行为</h1>
                <p class="text-xl leading-relaxed opacity-90">
                    掌握 Spring 框架中的事务传播机制，确保数据一致性与可靠性的关键技术
                </p>
                <div class="mt-8 flex justify-center space-x-4">
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-book-open mr-2"></i>深度解析
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-code mr-2"></i>实战示例
                    </span>
                    <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full text-sm">
                        <i class="fas fa-chart-line mr-2"></i>最佳实践
                    </span>
                </div>
            </div>
        </div>
    </section>

    <!-- Introduction Section -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto">
                <p class="text-lg leading-relaxed text-gray-700 indent-8">
                    <span class="font-bold text-xl highlight-text">Spring 事务传播行为</span>是 Spring 框架中的一个重要概念，用于定义在事务方法调用时，当前事务的传播规则。它决定了一个事务方法在调用另一个事务方法时的行为，以及如何处理不同事务之间的关系。事务传播行为对于确保数据的一致性和可靠性非常重要。
                </p>
            </div>
        </div>
    </section>

    <!-- Core Functions Section -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold mb-12 text-center">
                    <span class="highlight-text">事务传播行为的核心作用</span>
                </h2>
                
                <div class="grid md:grid-cols-3 gap-8">
                    <div class="bg-white rounded-xl p-8 card-hover">
                        <div class="feature-icon">
                            <i class="fas fa-border-all"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-4">定义事务边界</h3>
                        <p class="text-gray-600 leading-relaxed">
                            事务传播行为控制了事务的边界。在调用方法时，决定了是否使用现有事务，或创建新的事务，或其他处理方式。这帮助确保数据操作的一致性和完整性。
                        </p>
                    </div>
                    
                    <div class="bg-white rounded-xl p-8 card-hover">
                        <div class="feature-icon">
                            <i class="fas fa-shield-alt"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-4">确保数据一致性</h3>
                        <p class="text-gray-600 leading-relaxed">
                            在多层调用或复杂业务逻辑中，正确的事务传播行为能够确保在一个业务操作中出现的所有数据变化要么全部成功，要么全部回滚，从而保持数据的一致性。
                        </p>
                    </div>
                    
                    <div class="bg-white rounded-xl p-8 card-hover">
                        <div class="feature-icon">
                            <i class="fas fa-cogs"></i>
                        </div>
                        <h3 class="text-xl font-bold mb-4">提高事务的灵活性</h3>
                        <p class="text-gray-600 leading-relaxed">
                            不同的传播行为允许开发者根据具体的业务需求灵活地配置事务。例如，可以配置方法在调用时是否需要一个新的事务，或者是否在现有事务中继续执行。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Transaction Propagation Visualization -->
    <section class="py-16 bg-white">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold mb-12 text-center">
                    <span class="highlight-text">事务传播行为关系图</span>
                </h2>
                
                <div class="mermaid">
                    graph TD
                        A[调用方法] --> B{是否存在事务?}
                        B -->|是| C[REQUIRED<br/>加入当前事务]
                        B -->|否| D[REQUIRED<br/>创建新事务]
                        B -->|是| E[REQUIRES_NEW<br/>挂起当前事务<br/>创建新事务]
                        B -->|否| F[REQUIRES_NEW<br/>创建新事务]
                        B -->|是| G[NESTED<br/>创建嵌套事务]
                        B -->|否| H[NESTED<br/>创建新事务]
                        B -->|是| I[SUPPORTS<br/>加入当前事务]
                        B -->|否| J[SUPPORTS<br/>非事务执行]
                        B -->|是| K[NOT_SUPPORTED<br/>挂起当前事务<br/>非事务执行]
                        B -->|否| L[NOT_SUPPORTED<br/>非事务执行]
                        B -->|是| M[MANDATORY<br/>加入当前事务]
                        B -->|否| N[MANDATORY<br/>抛出异常]
                        B -->|是| O[NEVER<br/>抛出异常]
                        B -->|否| P[NEVER<br/>非事务执行]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </div>
    </section>

    <!-- Propagation Types Section -->
    <section class="py-16 bg-gray-50">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold mb-4 text-center">
                    <span class="highlight-text">Spring 提供的事务传播行为</span>
                </h2>
                <p class="text-center text-gray-600 mb-12 text-lg">
                    Spring 提供了以下几种事务传播行为，每种行为都有特定的应用场景和作用：
                </p>
                
                <!-- REQUIRED -->
                <div class="bg-white rounded-xl p-8 mb-8 shadow-lg">
                    <div class="flex items-center mb-6">
                        <span class="propagation-badge">REQUIRED</span>
                        <span class="ml-4 text-sm text-gray-500 font-medium">默认行为</span>
                    </div>
                    
                    <div class="code-block mb-6">
                        <pre><code>@Transactional(propagation = Propagation.REQUIRED)
public void performOperation() {
    // 业务逻辑
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-bold text-lg mb-2 flex items-center">
                                <i class="fas fa-info-circle mr-2 text-purple-600"></i>行为说明
                            </h4>
                            <p class="text-gray-600">如果当前存在事务，则加入当前事务；如果没有事务，则创建一个新的事务。</p>
                        </div>
                        <div>
                            <h4 class="font-bold text-lg mb-2 flex items-center">
                                <i class="fas fa-lightbulb mr-2 text-purple-600"></i>应用场景
                            </h4>
                            <p class="text-gray-600">适用于大多数业务操作，确保所有相关操作在一个事务中完成。</p>
                        </div>
                    </div>
                </div>

                <!-- REQUIRES_NEW -->
                <div class="bg-white rounded-xl p-8 mb-8 shadow-lg">
                    <div class="flex items-center mb-6">
                        <span class="propagation-badge">REQUIRES_NEW</span>
                    </div>
                    
                    <div class="code-block mb-6">
                        <pre><code>@Transactional(propagation = Propagation.REQUIRES_NEW)
public void performIndependentOperation() {
    // 业务逻辑
}</code></pre>
                    </div>
                    
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <h4 class="font-bold text-lg mb-2 flex items-center">
                                <i class="fas fa-info-circle mr-2 text-purple-600"></i>行为说明
                            </h4>
                            <p class="text-gray-600">总是创建一个新的事务。如果当前存在事务，则挂起当前事务，待新事务完成后再恢复。</p>
                        </div>